<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>用户注册</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f5f5f5;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .register-container {
            background-color: white;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            width: 400px;
            text-align: center;
        }
        h2 {
            color: #333;
            margin-bottom: 24px;
        }
        .form-group {
            margin-bottom: 20px;
            text-align: left;
        }
        label {
            display: block;
            margin-bottom: 6px;
            font-weight: 500;
            color: #555;
        }
        input[type="text"],
        input[type="password"],
        input[type="email"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
            font-size: 14px;
        }
        input[type="submit"] {
            width: 100%;
            padding: 12px;
            background-color: #4285f4;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }
        input[type="submit"]:hover {
            background-color: #3367d6;
        }
        .error-message {
            color: #d32f2f;
            margin-top: 15px;
            padding: 10px;
            background-color: #fde0e0;
            border-radius: 4px;
            font-size: 14px;
        }
        .footer {
            margin-top: 20px;
            font-size: 13px;
            color: #777;
        }
    </style>
</head>
<body>
<div class="register-container">
    <h2>用户注册</h2>

    <form action="doRegister.jsp" method="post">
        <div class="form-group">
            <label for="username">用户名</label>
            <input type="text" id="username" name="username" placeholder="请输入用户名(4-16位字母或数字)" required pattern="[A-Za-z0-9]{4,16}">
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" id="password" name="password" placeholder="请输入密码(6-20位字符)" required minlength="6" maxlength="20">
        </div>
        <div class="form-group">
            <label for="email">电子邮箱</label>
            <input type="email" id="email" name="email" placeholder="请输入有效邮箱地址" required>
        </div>

        <input type="submit" value="注册">
    </form>

    <%-- 错误消息显示 --%>
    <%
        String msg = (String)request.getAttribute("msg");
        if(msg != null) {
            out.print("<div class='error-message'>" + msg + "</div>");
        }
    %>

    <div class="footer">
        已有账号? <a href="login.jsp">立即登录</a>
    </div>
</div>
</body>
</html>